<html>
<head><meta charset="utf-8"><title>RA / Expand imports with attributes · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html">RA / Expand imports with attributes</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225363051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225363051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grégoire Geis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225363051">(Feb 05 2021 at 21:56)</a>:</h4>
<p>I'm trying to add support for attributes on import items to Rust Analyzer. One use case is to ignore import directives with the <a href="https://github.com/dtolnay/rustversion"><code>#[rustversion]</code></a> attribute, which works similarly to <code>#[cfg]</code>. Unfortunately only <code>cfg</code> attributes are processed right now (in <a href="https://github.com/rust-analyzer/rust-analyzer/blob/582a202d6ead6d2b793923c8f63801d34c72a448/crates/hir_def/src/nameres/collector.rs#L1027">https://github.com/rust-analyzer/rust-analyzer/blob/582a202d6ead6d2b793923c8f63801d34c72a448/crates/hir_def/src/nameres/collector.rs#L1027</a>). However there is some support for expanding proc-macros in this very file so I figured we can actually expand macros right there instead of only supporting <code>cfg</code>. The issue is that we would be processing macros earlier. Also we'd need to ignore some macros (eg. <code>cfg</code>, <code>stable</code>, <code>unstable</code>).</p>
<p>First of all, is expanding item macros so early a good idea? As previously stated it already kinda happens, just not for proc-macro attributes. I'm thinking of expanding macros in all cases and visiting (<code>collect</code>) their result recursively.</p>



<a name="225363568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225363568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225363568">(Feb 05 2021 at 22:01)</a>:</h4>
<p>This requires <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7049">https://github.com/rust-analyzer/rust-analyzer/pull/7049</a></p>



<a name="225363680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225363680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225363680">(Feb 05 2021 at 22:02)</a>:</h4>
<p>...which in turn requires tracking derive helpers so that they can be resolved (as-is, that PR causes a lot of false positives when using <code>#[serde]</code> on the item)</p>



<a name="225363740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225363740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225363740">(Feb 05 2021 at 22:02)</a>:</h4>
<p>Feel free to work on that actually!</p>



<a name="225363852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225363852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225363852">(Feb 05 2021 at 22:03)</a>:</h4>
<p>Oh this should probably be moved to <a class="stream" data-stream-id="185405" href="/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0">#t-compiler/wg-rls-2.0</a></p>



<a name="225364271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225364271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grégoire Geis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225364271">(Feb 05 2021 at 22:06)</a>:</h4>
<p>I'll look into it but that sounds harder than anticipated... I'll look into it if I have time, but I highly doubt I will.</p>
<p>Good point on the stream. I searched for "Rust-analyzer" and didn't realize that it was named wg-rls-2.0. Thanks for pointing out!</p>



<a name="225364435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/RA%20/%20Expand%20imports%20with%20attributes/near/225364435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/RA.20.2F.20Expand.20imports.20with.20attributes.html#225364435">(Feb 05 2021 at 22:08)</a>:</h4>
<p>yeah, this isn't very easy to implement</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>